/******************************************************************
 * Created by: DO HOANG HAI                                       
 * Date of Creation: 25/Aug/2007                                               
 * Date of last modification: 1st/Sep/2007
 * Status: Optimized and Finished
 *                                                                
 * Description: Provide interfaces to obtain and manage 
 * "item's comments" in the database                                 
 ******************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using Pbdms.Common.DataObject;
using Pbdms.DataAccess.DataProvider;

namespace Pbdms.BusinessLogic.DataController
{
    /// <summary>
    /// Provide interfaces to access "item's comments" in the database 
    /// </summary>
    public class CommentController
    {
        public CommentController()
        {
        }
        /// <summary>
        /// create an instance of type CommentContoller
        /// </summary>
        /// <returns></returns>
        public static CommentController create()
        {
            return new CommentController();
        }
        /// <summary>
        /// get comment of the object with given item's Id
        /// </summary>
        /// <param name="itemId">Id of the item</param>
        /// <returns>the corresponding comment object</returns>
        public Comment getCommentFromDB(String itemId)
        {
            Comment commentObj =  CommentProvider.create(itemId).selectFromDB();
            //add the path to the library folder
            if (!commentObj.ReviewFile.Trim().Equals(""))
                commentObj.ReviewFile = Common.Global.startupPath() + "\\Library\\" + commentObj.ReviewFile;
            return commentObj;
        }

        /// <summary>
        /// delete the comment in the database of the item with given Id
        /// </summary>
        /// <param name="itemObjId"></param>
        public void deleteComment(String itemObjId)
        {
            CommentProvider.create(itemObjId).deleteDB();
        }

        /// <summary>
        /// update "comment" of the item with newly given comment object
        /// </summary>
        /// <param name="commentObj"></param>
        public void updateCommentToDB(Comment commentObj)
        {
            //remove the path to the library, just store the file name (for portable to copy database)
            commentObj.ReviewFile = commentObj.ReviewFile.Substring(commentObj.ReviewFile.LastIndexOf("\\") + 1);
            //update the database
            CommentProvider.create(commentObj).updateAllToDB();
        }
        /// <summary>
        /// append a new comment object to database
        /// </summary>
        /// <param name="commentObj">Comment object to be appended</param>
        public void appendComment(Comment commentObj)
        {
            CommentProvider.appendComment(commentObj);
        }
    }
}
